<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/13
 * Time: 15:51
 */

if (!defined('IN_IA')) {
    exit('Access Denied');
}

class Bonus_MxShopPage extends WebPage {

    public function main(){

        global $_W,$_GPC;
        $id = intval($_GPC['id']);

        if(empty($id)){
            show_json(0,'参数有误！');
        }
        $platform = pdo_fetch("SELECT * FROM " . tablename('mx_shop_platform') . " WHERE platformid=:platformid", array('platformid'=>$id));

        if ($_W['ispost']) {

            $data = array();
            $data['moneyman'] = abs($_GPC['moneyman']);
            $data['store'] = abs($_GPC['store']);
            $data['country'] = abs($_GPC['country']);
            $data['province'] = abs($_GPC['province']);
            $data['city'] = abs($_GPC['city']);
            $data['area'] = abs($_GPC['area']);
            $data['cashback'] = abs($_GPC['cashback']);
            $data['recommend'] = abs($_GPC['recommend']);
            $data['recommend2'] = abs($_GPC['recommend2']);
            $data['recommend3'] = abs($_GPC['recommend3']);
            $data['channel'] = abs($_GPC['channel']);
            $data['supplier'] = abs($_GPC['supplier']);
            $data['producer'] = abs($_GPC['producer']);
            $data['foundation'] = abs($_GPC['foundation']);
            $data['company'] = abs($_GPC['company']);
            $data['technology'] = abs($_GPC['technology']);

            $num = 0;
            foreach ($data as $val){
                $num += $val;
            }

            if(ceil($num) > 100){
                show_json(0,'行业分红不能超过100%！');
            }

            //设置网关分红
            $res = m('platform')->setPlatformBonusToProxy($id, $data);
            if($res['code'] != 0){
                show_json(0, $res['msg']);
            }

            plog('platform.manage.bonus', '更新平台分红成功！平台分红ID为' . $id);

            show_json(1, array('url'=>webUrl('platform')));
        }

        //获取网关分润信息
        $res = m('platform')->getPlatformBonusToProxy($id);
        if($res['code'] != 0){
            message($res['msg']);
        }

        $item = $res['data'];

        include $this->template();

    }

}
